<?php

namespace plugins\admin_status\controller;

use cmf\controller\PluginBaseController;
use think\Validate;

class AdminStatusController extends PluginBaseController
{
    function setpassword()
    {
        $arrData = $this->request->post();
        $validate = new Validate([
            'password' => 'require|min:6|max:32',
            'password_check' => 'require',
        ]);
        $validate->message([
            'password.require' => '密码不能为空',
            'password.max'     => '密码不能超过32个字符',
            'password.min'     => '密码不能小于6个字符',
            'password_check.require' => '确认密码不能为空',
        ]);

        if (!$validate->check($arrData)) {
            $this->error($validate->getError());
        }
        if($arrData['password'] == $arrData['password_check']) {
            db('user')->where(['id' => cmf_get_current_admin_id()])->update([
                'user_status' => 1,
                'user_pass' => cmf_password($arrData['password']),
            ]);
            $this->success('密码修改成功');
        }else{
            $this->error('两次输入密码不一致');
        }
    }
}